/** * 审核详情 */
<template>
  <view class="container">
    <business v-if="isShow.isBusiness" :form="form"></business>
	<reimbursement v-if="isShow.isReimbursement" :form="form"></reimbursement>
	<expend v-if="isShow.isExpend" :form="form"></expend>
	<invoicing v-if="isShow.isInvoicing" :form="form"></invoicing>
	<leave v-if="isShow.isLeave" :form="form"></leave>
	<useSeal v-if="isShow.isUseSeal" :form="form"></useSeal>
	<payment v-if="isShow.isPayment" :form="form"></payment>
	<bidding v-if="isShow.isBidding" :form="form"></bidding>
    <view class="btns">
      <u-button
        shape="square"
        type="primary"
        size="medium"
        :ripple="true"
        @click="pass"
        >通过</u-button
      >
      <u-button shape="square" type="info" size="medium" :ripple="true"
        >驳回</u-button
      >
    </view>
    <u-popup
      v-model="popupShow"
      mode="center"
      border-radius="14"
      width="270px"
      height="200px"
    >
      <view style="padding: 15px">
        <u-form :model="passForm" ref="uForm" label-width="130">
          <u-form-item label="审批意见"
            ><u-input v-model="passForm.suggestion" type="textarea" height="50"
          /></u-form-item>
          <u-form-item label="消息通知" :border-bottom="false">
            <u-checkbox-group>
              <u-checkbox
                v-model="item.checked"
                v-for="(item, index) in checkboxList"
                :key="index"
                :name="item.name"
              >
                {{ item.name }}
              </u-checkbox>
            </u-checkbox-group>
          </u-form-item>
        </u-form>
        <view class="btns">
          <u-button
            type="primary"
            shape="square"
            size="medium"
            :ripple="true"
            @click="submit"
            >提交</u-button
          >
          <u-button
            type="info"
            shape="square"
            size="medium"
            :ripple="true"
            @click="popupShow = false"
            >取消</u-button
          >
        </view>
      </view>
    </u-popup>
    <u-toast ref="uToast" />
  </view>
</template>

<script>
import auditApi from "../../api/audit.js";
import business from "../../components/examine/business.vue"
import reimbursement from "../../components/examine/reimbursement.vue"
import expend from "../../components/examine/expend.vue"
import invoicing from "../../components/examine/invoicing.vue"
import leave from "../../components/examine/leave.vue"
import useSeal from "../../components/examine/useSeal.vue"
import payment from "../../components/examine/payment.vue"
import bidding from "../../components/examine/bidding.vue"
export default {
	components:{
		business,
		reimbursement,
		expend,
		invoicing,
		leave,
		useSeal,
		payment,
		bidding
	},
  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  onReady() {
    this.$refs.uForm.setRules(this.rules);
  },
  mounted() {
    console.log('路由参数',this.$Route.query);
    const {
      name,
      processName,
      assignee,
      applyer,
      isSuspended,
      status,
      createTime,
    } = this.$Route.query.obj;
	
	this.form.table.tableId=this.$Route.query.obj.tableId;
	this.form.table.tableName=this.$Route.query.obj.tableName;

    this.form.name = name;
    this.form.belong = processName || "无";
    this.form.client = assignee || "无";
    this.form.initiator = applyer;
    this.form.priority = isSuspended ? "延期" : "普通";
    this.form.status = 1 ? "已激活" : "未激活";
    this.form.time = createTime;
	this.processJudgment(processName)
  },
  data() {
    return {
		isShow:{
			isBusiness:false,
			isReimbursement:false,
			isExpend:false,
			isInvoicing:false,
			isLeave:false,
			isUseSeal:false,
			isPayment:false,
			isBidding:false
		},
      form: {
        // 任务名称
        name: "",
        // 所属流程
        belong: "",
        // 委托人
        client: "",
        // 流程发起人
        initiator: "",
        // 优先级
        priority: "",
        // 状态
        status: "",
        // 表单创建时间
        time: "",
		table:{
			tableId:undefined,
			tableName:undefined
		}
      },
      // 弹出框的显示
      popupShow: false,
      // 弹出框内表单数据
      passForm: {
        // 审批意见
        suggestion: "",
      },
      // 弹出框内表单checkbox数据
      checkboxList: [
        {
          name: "站内消息通知",
          checked: false,
          disabled: false,
        },
        {
          name: "短信通知",
          checked: false,
          disabled: false,
        },
        {
          name: "邮件通知",
          checked: false,
          disabled: false,
        },
      ],
      // 弹出框内表单验证
      rules: {
        leaveApplicant: [
          {
            required: true,
            message: "请输入请假人",
            trigger: "blur,change",
          },
        ],
        reasonForLeave: [
          {
            required: true,
            message: "请说明请假原因",
            trigger: "blur,change",
          },
        ],
      },
    };
  },
  methods: {
	// 判断流程类型
	processJudgment(pName){
		switch(pName){
			case "业务流程":
			this.isShow.isBusiness = true
			break;
			case "报销流程":
			this.isShow.isReimbursement = true
			break;
			case "用款流程":
			this.isShow.isExpend = true
			break;
			case "开票流程":
			this.isShow.isInvoicing = true
			break;
			case "请假流程":
			this.isShow.isLeave = true
			break;
			case "用章流程":
			this.isShow.isUseSeal = true
			break;
			case "付款流程":
			this.isShow.isPayment = true
			break;
			case "招标信息流程":
			this.isShow.isBidding = true
			break;
			default:
			return
		}
	},
    // 显示提示框
    showToast(title, type) {
      this.$refs.uToast.show({
        title,
        type,
        position: "top",
      });
    },
    // 通过按钮的回调
    pass() {
      this.popupShow = true;
    },
    // 提交表单的回调
    submit() {
      auditApi
        .passDetail(
          {
            "X-Access-Token": this.$store.state.token,
          },
          {
            assignees: "",
            priority: "",
            id: this.$Route.query.obj.id,
            procInstId: this.$Route.query.obj.procInstId,
            comment: this.passForm.suggestion,
            sendMessage: this.checkboxList[0].checked,
            sendSms: this.checkboxList[1].checked,
            sendEmail: this.checkboxList[2].checked,
          }
        )
        .then((res) => {
          console.log(res.data.code);
          if (res.data.code === 200) {
            this.showToast("提交成功", "success");
            this.$Router.replaceAll("/pages/processCate/processCate");
          } else {
            this.showToast("提交失败", "error");
          }
        });
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  width: 90%;
  margin: 0 auto;
  .btns {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
  }
}
</style>
